﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PaymentToVendor.ascx.cs" Inherits="Gollie.Controls.Admin.PaymentToVendor" %>
<%@ Register Src="~/Controls/MonthPickerControl.ascx" TagPrefix="uc1" TagName="MonthPickerControl" %>
<%@ Register Src="~/Controls/YearPickerControl.ascx" TagPrefix="uc1" TagName="YearPickerControl" %>

<asp:HiddenField ID="tbIsRefreshed" ClientIDMode="Static" runat="server" Value="1"/>

<div id="dialog-help" title="Help" class="dialog-help">
    <span>No actions have been performed, because the chosen period did not match the period in the table.<br />
    <br />
     Most likely, you forgot to click 'Refresh' after selecting a period.
    </span>
</div>

<p class="title">Vendor deposits and payments</p>

<table style="width:1px; border: 1px solid black;">
    <tr><td style="padding-bottom: 8px; font-weight:bold; font-size: 1.2em;">Select period</td></tr>
    <tr>
        <td><uc1:MonthPickerControl runat="server" ID="MonthPickerControl" /></td>
        <td><uc1:YearPickerControl runat="server" ID="YearPickerControl" /></td>
        <td><asp:Button ID="btnPeriod" runat="server" Text="Refresh" UseSubmitBehavior="false" OnClick="btnPeriod_Click"/></td>
    </tr>
</table>
<br />

<div style="float:left; font-size: 1.3em; font-weight: bold; padding-left: 32px; padding-bottom: 4px;">
    <span>Period: </span>
    <asp:Label ID="lblPeriodMonth" runat="server"></asp:Label>
    <asp:Label ID="lblPeriodYear" runat="server"></asp:Label>
</div>
<div style="float:right; font-size: 1.1em; padding-bottom: 4px;">
 <asp:Button ID="btnRegisterAllPayments" runat="server" Text="Register all payments at once" UseSubmitBehavior="false" OnClick="btnRegisterAllPayments_Click" OnClientClick="if (confirm('All payments will be registered. Make sure all banktransfers have been done!') == false) return false;"/>
</div>

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" DataKeyNames="VendorId" OnDataBinding="GridView1_DataBinding" OnRowDataBound="GridView1_RowDataBound" HorizontalAlign="Center" ShowFooter="True" ShowHeaderWhenEmpty="True" Width="100%" AllowSorting="True" OnSorting="GridView1_Sorting" OnRowCommand="GridView1_RowCommand">
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        <Columns>
            <asp:TemplateField ItemStyle-Width="160px" HeaderText="Vendor" FooterText="Totaal" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign ="Left" FooterStyle-HorizontalAlign="Right">
                <ItemTemplate>
                    <table style="width: 100%;">
                        <tr>
                            <td style="text-align: left; vertical-align: top;">
                                <asp:Panel ID="pnlExpandCollapseImage" runat="server">
									<img class='expand-collapse' targetid='divvendorname<%# Eval("VendorId")%>'/>
                                </asp:Panel>
                           </td>
                            <td style="text-align: left; vertical-align: top;">
                                <span><%# Eval("Billingname")%></span>
                            </td>
                        </tr>
                    </table>
                    <div id='divvendorname<%# Eval("VendorId")%>' style="display: none;">
                        <table style="width: 100%;">
                            <tr>
                                <td style="text-align: left; vertical-align: top;"><%# Eval("Billingcity")%>
                            </tr>
                            <tr>
                                <td style="text-align: left; vertical-align: top;"><%# Eval("Billingaccount")%>
                            </tr>
                            <tr>
                                <td style="text-align: left; vertical-align: top;"><%# Eval("Billingemail")%>
                            </tr>
                        </table>
                    </div>
                </ItemTemplate>
                
<FooterStyle HorizontalAlign="Right"></FooterStyle>

<HeaderStyle HorizontalAlign="Left"></HeaderStyle>

                <ItemStyle CssClass="offer-grid-cell" />
            </asp:TemplateField>

            <asp:BoundField DataField="Deposits" HeaderText="Deposits" DataFormatString="{0:c2}" SortExpression="Deposits">
            <HeaderStyle CssClass="admin-header-right"/>
            <ItemStyle CssClass="offer-grid-cell" />
            <FooterStyle HorizontalAlign="Right"/>
            </asp:BoundField>

            <asp:TemplateField HeaderText="Amount for vendor" ItemStyle-HorizontalAlign="Right" SortExpression="ToPay">
                <ItemTemplate>
                    <table style="width: 100%;">
                        <tr>
                            <td style="text-align: left; vertical-align: top;">
                                <asp:Panel ID="pnlExpandCollapseImage2" runat="server">
									<img class='expand-collapse' targetid='divamountforvendor<%# Eval("VendorId")%>'/>
                                </asp:Panel>
                           </td>
                            <td style="text-align: right; vertical-align: top;">
                                <span><%# string.Format("{0:c2}", Eval("ToPay"))%></span>
                            </td>
                        </tr>
                    </table>
                    <div id='divamountforvendor<%# Eval("VendorId")%>' style="display: none;">
                        <table style="width: 100%;">
                            <tr>
                                <td style="text-align: right; vertical-align: top;">Gollie fee:</td>
                                <td style="text-align: right; vertical-align: top;"><%# string.Format("{0:c2}", Eval("Grossfee"))%></td>
                            </tr>
                            <tr>
                                <td style="text-align: right; vertical-align: top;">Discount:</td>
                                <td style="text-align: right; vertical-align: top;"><%# string.Format("{0:c2}", Eval("Totaldiscount"))%></td>
                            </tr>
                            <tr>
                                <td style="text-align: right; vertical-align: top;">BTW:</td>
                                <td style="text-align: right; vertical-align: top;"><%# string.Format("{0:c2}", Eval("Totalvat"))%></td>
                                    <br></br>
                            </tr>
                        </table>
                    </div>
                </ItemTemplate>
                <HeaderStyle CssClass="admin-header-right" />
                <ItemStyle CssClass="offer-grid-cell" />
                <FooterStyle HorizontalAlign="Right"/>
            </asp:TemplateField>


            <asp:BoundField DataField="Alreadypaid" HeaderText="Already paid" DataFormatString="{0:c2}" SortExpression="Alreadypaid">
            <HeaderStyle CssClass="admin-header-right" />
            <ItemStyle CssClass="offer-grid-cell" />
            <FooterStyle HorizontalAlign="Right"/>
            </asp:BoundField>


            <asp:BoundField DataField="Lefttopay" DataFormatString="{0:c2}" HeaderText="Left to pay" SortExpression="Lefttopay">
            <HeaderStyle CssClass="admin-header-right" />
            <ItemStyle CssClass="offer-grid-cell" />
            <FooterStyle HorizontalAlign="Right"/>
            </asp:BoundField>

            <asp:TemplateField HeaderText="Register payment">
                <ItemTemplate>
                    <asp:Button runat="server" ID="btnRegisterPayment" Font-Size="Smaller"
                        CommandName="RegisterPayment"
                        CommandArgument='<%# Eval("VendorId") %>'
                        Text="Register this amount"
                        OnClientClick='<%# String.Format("return confirm(\"Register a payment of {0:c2} to {1}? \\nMake sure the bank transfer has been done!\");", Eval("Lefttopay"),  Eval("Billingname")) %>'
                         />
                </ItemTemplate>
                <ItemStyle VerticalAlign="Top" />
            </asp:TemplateField>
            


          </Columns>
        <EditRowStyle BackColor="#999999" />
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#E9E7E2" />
        <SortedAscendingHeaderStyle BackColor="#506C8C" />
        <SortedDescendingCellStyle BackColor="#FFFDF8" />
        <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
    </asp:GridView>